package com.FindImportKeys.Utils;

import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.*;
import java.util.List;



public class WriteDoc {
    private static String errorWordFilePath = "importWordErrorDetails.doc";
    /**
     * 写导入题库错误文件类容
     * @param fileDir    文件路径
     * @param filePath   文件路径
     * @param content    内容
     * @param type       文件类型  1---excel 2 word;
     * @author niugang
     */
    private void writerErrorFileContent(String fileDir, String filePath, String content, String type) throws IOException {
        XWPFDocument document = new XWPFDocument();
        OutputStream stream = null;
        BufferedOutputStream bufferStream = null;
        try {
            File dir = new File(fileDir);
            if (!dir.exists()) {
                dir.mkdirs();
            }
            stream = new FileOutputStream(new File(fileDir+filePath));
            bufferStream = new BufferedOutputStream(stream, 1024);
            // 创建一个段落
            XWPFParagraph p1 = document.createParagraph();
            // 设置居中
            p1.setAlignment(ParagraphAlignment.CENTER);
            XWPFRun r1 = p1.createRun();
            // 是否加粗
            r1.setBold(true);
            // 与下一行的距离
            r1.setTextPosition(30);

            // 字体大小
            r1.setFontSize(18);// 字体大小
            // 增加换行
            r1.addCarriageReturn();

//            // 创建第二个段落
//            XWPFParagraph p2 = document.createParagraph();
//            XWPFRun r2 = p2.createRun();
//            // 设置字体
//            r2.setFontFamily("仿宋");
//            r2.setFontSize(14);// 字体大小

            document.write(stream);
            bufferStream.close();
        } catch (Exception ex) {
            throw new RuntimeException("写入错误" );
        }finally {
            stream.close();

        }
    }
}
